package com.epfresh.supplier.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.BookGoodsYear;

import java.util.List;

/**
 * Created by wzh on 2016/5/6.
 */
public class BookGoodsYearAdapter extends BaseAdapter {//} implements View.OnClickListener{

    public Context context;

    public List<BookGoodsYear.MonthIncomeListBean> list;


    private View.OnClickListener onItemClickListener;

    public BookGoodsYearAdapter(Context context , List<BookGoodsYear.MonthIncomeListBean> list) {
        this.context = context;
        this.list = list;
    }

    public View.OnClickListener getOnItemClickListener() {
        return onItemClickListener;
    }

    public void setOnItemClickListener(View.OnClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getCount() {
        return list != null ?list.size():0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null) {
            vh = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_year_goods_sell_detail, null, false);

            vh.tvMoney = (TextView) convertView.findViewById(R.id.tv_money);
            vh.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
            vh.ll_item = convertView.findViewById(R.id.ll_item);

            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }

        BookGoodsYear.MonthIncomeListBean data = list.get(position);
        vh.tvTime.setText(data.getName());
        vh.tvMoney.setText(""+data.getPrice()+"元");
        vh.ll_item.setTag(R.id.item_key_position, position);
        vh.ll_item.setOnClickListener(onItemClickListener);

        return convertView;
    }
/*
    @Override
    public void onClick(View v) {
        Object o = v.getTag(R.id.item_key_position);
        if (o != null && o instanceof Integer){
            if (onItemClickListener != null) {
                int position = (int) o;
                //onItemClickListener.onItemClick(null, v, position, position);
            }
        }
    }
*/

    public class ViewHolder {

        TextView tvTime;
        TextView tvMoney;
        View ll_item;

    }
}
